package com.codeczx.completeuidemo.search;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.ListView;
import android.widget.SearchView;

import com.codeczx.completeuidemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OfficialSearchViewActivity extends AppCompatActivity {

    @BindView(R.id.search_view)
    SearchView searchView;
    @BindView(R.id.list_view)
    ListView listView;

    private String[] mStrs = {"a","b","c","d"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_official_search_view);
        ButterKnife.bind(this);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,mStrs);
        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(false);
        final Filter filter = adapter.getFilter();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                filter.filter(newText);
                return false;
            }
        });
    }
}
